package com.iamback.dy.examine.controller.admin.report;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iamback.dy.entity.ContentExamineByTypeCount;
import com.iamback.dy.entity.ContentExamineTotalCount;
import com.iamback.dy.examine.common.Page;
import com.iamback.dy.examine.controller.BaseController;
import com.iamback.dy.examine.service.IContentCountService;
import com.iamback.dy.examine.vo.ContentCountRate;

/**
 * 帖子统计
 */

@Controller
@RequestMapping("/report/content")
public class ReportContentController  extends BaseController {
	@Autowired
	private IContentCountService contentCountService;
	
	@RequestMapping("/examine/user/show")
	public String showExamineContentCount(){
		return "report/examineUserReport";
	} 
	
	@RequestMapping("/examine/result/show")
	public String showExamineContentResultCount(){
		return "report/examineResultReport";
	} 
	@RequestMapping("/examine/total/show")
	public String showExamineContentTotalCount(){
		return "report/examineTotaReport";
	} 
	/**
	 * 用户审核统计
	 * @param userName
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/examine/user/count")
	public List<ContentCountRate> examineContentCount(String userName,String startDate ,String endDate){
//	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//	        //获取String类型的时间
		Date createdate =null;
		Date endDates =null;
		if(startDate!=null){createdate = strToDateLong(startDate);}
	    if(endDate !=null){endDates = strToDateLong(endDate);}
		List<ContentCountRate>  page =contentCountService.countRate(userName, createdate, endDates, 0, 1000);
		return page;
	}
	
	/**
	 * 审核结果统计
	 * @param userName  用户名
	 * @param dateType  统计时间节点分组（1:日，2:月）
	 * @param startDate 开始时间
	 * @param endDate   结束时间
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/examine/result/count")
	public List<ContentExamineByTypeCount> ContentExamineByTypeCount(String userName,
			String dateType, String startDate, String endDate){
		Date createdate =null;
		Date endDates =null;
		if(startDate!=null){createdate = strToDateLong(startDate);}
	    if(endDate !=null){endDates = strToDateLong(endDate);}
	    
	   return contentCountService.findContentExamineByType(userName, dateType, createdate, endDates);
	}
	
	
	@ResponseBody
	@RequestMapping("/examine/total/count")
	public List<ContentExamineTotalCount> findContentExamineTotalCount(String startDate, String endDate){
		Date createdate =null;
		Date endDates =null;
		if(startDate!=null){createdate = strToDateLong(startDate);}
	    if(endDate !=null){endDates = strToDateLong(endDate);}
		return contentCountService.findContentExamineTotalCount(createdate, endDates);
	}
	
	
	public static Date strToDateLong(String strDate) {
	    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	    ParsePosition pos = new ParsePosition(0);
	    Date strtodate = formatter.parse(strDate, pos);
		return strtodate;
	 }
	
	
	
}
